#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "comm.hpp"


//进行写入
int main()
{
    //打开文件
    int fd = open(FIFO_FIFO,O_WRONLY);
    if(fd < 0)
    {
        std::cout<<"open fifo error"<<std::endl;
        return 1;
    }
    std::cout<<"open fifo successful"<<std::endl;

    //进行写入
    std::string message;
    int cnt = 1;
    pid_t id = getpid();
    std::cout<<"Place Enter---"<<std::endl;
    while(true)
    {
        std::getline(std::cin,message);
        message += (",message number") + std::to_string(cnt++) + ",[" + std::to_string(id) + "]";
        write(fd,message.c_str(),message.size());
    }
    //关闭文件
    close(fd);
    return 0;
}